package com.ovopark.firecar.config;

import androidx.annotation.IntDef;


import com.ovopark.firecar.bean.User;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * 获取 USER 信息
 * Created by cz on 2019/6/3.
 */
public class UserConfig {
    public static final int USER_ID = 1;
    public static final int USER_TOKEN = 2;
    public static final int USER_GROUP_ID = 3;
    public static final int USER_ENTERPRISE_ID = 4;
    public static final int USER_SHOW_NAME = 5;
    public static final int USER_USER_NAME = 6;
    public static final int USER_GRADE_ID = 7;
    public static final int USER_THRUMB_URL = 8;

    @Documented
    @IntDef({
            USER_ID,
            USER_TOKEN,
            USER_GROUP_ID,
            USER_ENTERPRISE_ID,
            USER_SHOW_NAME,
            USER_USER_NAME,
            USER_GRADE_ID,
            USER_THRUMB_URL
    })
    @Target({
            ElementType.PARAMETER,
            ElementType.FIELD,
            ElementType.METHOD,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface UserDef {
    }

    public static String getUserByDef(User user, @UserDef int userDef) {
        try {
            if (user != null) {
                switch (userDef) {
                    case USER_ID:
                        return String.valueOf(user.getId());

                    case USER_GROUP_ID:
                        return user.getGroupId();

                    case USER_TOKEN:
                        return user.getToken();

                    case USER_ENTERPRISE_ID:
                        return user.getEnterpriseId();

                    case USER_SHOW_NAME:
                        return user.getShowName();

                    case USER_USER_NAME:
                        return user.getUserName();

                    case USER_GRADE_ID:
                        return String.valueOf(user.getGradeId());

                    case USER_THRUMB_URL:
                        return user.getThumbUrl();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            //TODO BUGLY UPLOAD
        }
        return "";
    }
}